<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="<%= path %>/public/extjs/resources/css/ext-all.css" />
<link rel="stylesheet" type="text/css" href="<%= path %>/public/css/icon.css" />
<link rel="stylesheet" type="text/css" href="<%= path %>/public/extux/LovCombo.css" />
</head>
<body topmargin="0">
<script type="text/javascript" src="<%= path %>/public/extjs/adapter/ext/ext-base.js"></script> 
<script type="text/javascript" src="<%= path %>/public/extjs/ext-all.js"></script> 
<script type="text/javascript" src="<%= path %>/public/extux/LovCombo.js"></script> 
<div id="main" style="margin:10 0 0 10;"></div>
<div id="main2" style="margin:10 0 0 10;"></div>
<script type="text/javascript" >
	Ext.BLANK_IMAGE_URL  =  '<%= path %>/public/extjs/resources/images/default/s.gif';
	Ext.QuickTips.init();
	var pathUrl = '<%= path %>'; //该变量必须存在
	Ext.onReady(function(){
		//列模型
		var sm = new Ext.grid.CheckboxSelectionModel();
		var columnModel=new Ext.grid.ColumnModel([
       		new Ext.grid.RowNumberer(),
       		{header:"作业流ID",dataIndex:"flowId",width:100,sortable: true},
       		{header:"作业流名称",dataIndex:"flowName",width:180,sortable: true},
       		{header:"运行状态",dataIndex:"status",width:100,sortable: true,renderer:rendStatus},
       		{header:"完成数据时间",dataIndex:"runFirst",width:100,sortable: true},
       		{header:"运行数据时间",dataIndex:"runFirst",width:100,sortable: true},
       		{header:"平均运行时间",dataIndex:"runFirst",width:100,sortable: true},
       		{header:"进度",dataIndex:"runFirst",width:100,sortable: true}
       	]);
		//工具条
       	var ttbar=new Ext.Toolbar({
			width:600
         });
      	//数据来源
		var store=new Ext.data.Store({
			proxy:new Ext.data.HttpProxy({
			    url:pathUrl+"/listFlows.do"
			}),
			reader:new Ext.data.JsonReader(
				{
					totalProperty:"count",
					successProperty:"ready",
					root:"list"},
				[
				 {name:"flowId",mapping:"flowId"},
				 {name:"flowName",mapping:"flowName"},
				 {name:"runFirst",mapping:"runFirst"},
				 {name:"status",mapping:"status"}
				])
		});
		function rendStatus(value){
			if(value=='1'){
				return '正在运行';
			}else if(value=='0'){
				return '空闲';
			}else if(value=='2'){
				return '错误';
			}
		}
		var gridTable=new Ext.grid.GridPanel({
		  	title:'作业流列表',
		  	height : 260,
			width : 880,
			bodyStyle:'padding:5px',
			loadMask : true,
			pruneModifiedRecords:true,
			store:store,
			cm:columnModel,
			sm:sm,
   			bbar:new Ext.PagingToolbar({
   	            pageSize: 10,    
   	            store: store,    
   	            displayInfo: true,    
   	            displayMsg: '显示第 {0} 条到 {1} 条记录，一共 {2} 条',    
   	            emptyMsg: "没有记录"   
   	        })
			
		});
		store.load({params:{start:0,limit:10}}); 
		function save(){
			var m=store.getModifiedRecords();
			store.commitChanges();
			var jsonArray=[];
			Ext.each(m,function(item){
				jsonArray.push(item.data);
			});
			Ext.Ajax.request({
				method:'post',
				params:{ datas: Ext.util.JSON.encode(jsonArray) },
				url:pathUrl+'/saveFlows.do',
				success : function(action) {
					Ext.Msg.alert(
						'提示信息','操作成功！',
						function(){
							store.reload();
							lovStore.reload();
						}
					);
				},
	            failure: function (f,v){
	                Ext.MessageBox.show({
	                    title: '失败',
	                    msg: '保存失败，请重试！',
	                    buttons: Ext.MessageBox.OK,
	                    icon: Ext.MessageBox.ERROR
	                });
	            },
	            waitMsg: '正在处理数据，请稍后……',
	            scope: this
			});
		}
		gridTable.render("main");
		var flowId;
		gridTable.store.on("load",function(){  
			gridTable.getSelectionModel().selectFirstRow(); 
			flowId = gridTable.getSelections()[0].get('flowId');
			store2.load({params:{start:0,limit:100,flowId:flowId}});
	    });  
		gridTable.on('cellclick', function(store,e) { 
			flowId = gridTable.getSelections()[0].get('flowId');
			store2.load({params:{start:0,limit:100,flowId:flowId}});
	    });

	    
		//--------------------------------------------------------------------
		
		var sm2 = new Ext.grid.CheckboxSelectionModel();
		var columnModel2=new Ext.grid.ColumnModel([
       		new Ext.grid.RowNumberer(),
			{header:"作业ID",dataIndex:"jobId",width:100,sortable: true},
       		{header:"作业名称",dataIndex:"jobName",width:180,sortable: true},
       		{header:"作业类型",dataIndex:"jobType",width:100,sortable: true},
       		{header:"执行顺序",dataIndex:"jobSeq",width:100,sortable: true}
       	]);
		//数据来源
		var store2=new Ext.data.Store({
			proxy:new Ext.data.HttpProxy({
			    url:pathUrl+"/listJobsByFlow.do"
			}),
			reader:new Ext.data.JsonReader(
				{
					totalProperty:"count2",
					root:"flowList"},
				[
				 {name:"id",mapping:"id"},
				 {name:"jobId",mapping:"jobId"},
				 {name:"jobName",mapping:"jobName"},
				 {name:"jobType",mapping:"jobType"},
				 {name:"jobSeq",mapping:"jobSeq"}
				])
		});
		var gridTable2=new Ext.grid.GridPanel({
		  	title:'作业列表',
		  	height : 260,
			width : 580,
			bodyStyle:'padding:5px',
			loadMask : true,
			pruneModifiedRecords:true,
			store:store2,
			cm:columnModel2,
			sm:sm2,
   			bbar:new Ext.PagingToolbar({    
   	            pageSize: 10,    
   	            store: store2,    
   	            displayInfo: true,    
   	            displayMsg: '显示第 {0} 条到 {1} 条记录，一共 {2} 条',    
   	            emptyMsg: "没有记录"   
   	        })
			
		});
		gridTable2.render("main2");
	});
</script>
</body>

</html>

